home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / Xsun / RCS / sunInit.c,v < prev    next >
Encoding:
Text File  |  1992-08-07  |  20.9 KB  |  854 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    jhh:1.6; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     92.08.07.13.03.55;  author rab;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     91.01.08.23.00.09;  author mgbaker;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     90.07.24.18.01.11;  author mgbaker;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     90.07.11.13.45.36;  author mendel;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     90.03.19.16.30.46;  author tve;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     90.02.16.17.40.10;  author tve;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @Original X11R4 distribution
  42. @
  43.  
  44.  
  45. 1.6
  46. log
  47. @checking in for rab
  48. @
  49. text
  50. @/*-
  51.  * sunInit.c --
  52.  *    Initialization functions for screen/keyboard/mouse, etc.
  53.  *
  54.  * Copyright (c) 1987 by the Regents of the University of California
  55.  *
  56.  * Permission to use, copy, modify, and distribute this
  57.  * software and its documentation for any purpose and without
  58.  * fee is hereby granted, provided that the above copyright
  59.  * notice appear in all copies.  The University of California
  60.  * makes no representations about the suitability of this
  61.  * software for any purpose.  It is provided "as is" without
  62.  * express or implied warranty.
  63.  *
  64.  *
  65.  */
  66.  
  67. /************************************************************
  68. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  69.  
  70.                     All Rights Reserved
  71.  
  72. Permission  to  use,  copy,  modify,  and  distribute   this
  73. software  and  its documentation for any purpose and without
  74. fee is hereby granted, provided that the above copyright no-
  75. tice  appear  in all copies and that both that copyright no-
  76. tice and this permission notice appear in  supporting  docu-
  77. mentation,  and  that the names of Sun or MIT not be used in
  78. advertising or publicity pertaining to distribution  of  the
  79. software  without specific prior written permission. Sun and
  80. M.I.T. make no representations about the suitability of this
  81. software for any purpose. It is provided "as is" without any
  82. express or implied warranty.
  83.  
  84. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  85. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  86. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  87. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  88. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  89. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  90. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  91. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  92.  
  93. ********************************************************/
  94.  
  95. #ifndef    lint
  96. static char sccsid[] = "%W %G Copyright 1987 Sun Micro";
  97. #endif
  98.  
  99. #include    "sun.h"
  100. #include    <signal.h>
  101. #include    <servermd.h>
  102. #include    "dixstruct.h"
  103. #include    "dix.h"
  104. #include    "opaque.h"
  105. #include    "mipointer.h"
  106.  
  107. #define    R_OK    4
  108. #define    W_OK    2
  109. #define    X_OK    1
  110. #define    F_OK    0
  111.  
  112. #include "sys/ioctl.h"
  113. #include "fcntl.h"
  114.  
  115. extern int sunMouseProc();
  116. extern int sunKbdProc();
  117. extern Bool sunBW2Probe(), sunBW2Create();
  118. #ifndef    sprite
  119. extern Bool sunCG2CProbe(), sunCG2CCreate();
  120. #endif    sprite
  121. extern Bool sunCG3CProbe(), sunCG3CCreate();
  122. extern Bool sunCG4CProbe(), sunCG4CCreate();
  123. extern Bool sunCG6CProbe(), sunCG6CCreate();
  124. extern void ProcessInputEvents();
  125.  
  126. extern void SetInputCheck();
  127. extern char *strncpy();
  128. extern GCPtr CreateScratchGC();
  129.  
  130. #define    XDEVICE    "XDEVICE"
  131. #define    PARENT    "WINDOW_GFX"
  132.  
  133. int spriteCheckInput = 0;     /* For use with SetInputCheck */
  134. static int autoRepeatHandlersInstalled;    /* FALSE each time InitOutput called */
  135.  
  136. static Bool sunDevsProbed = FALSE;
  137. Bool sunSupportsDepth8 = FALSE;
  138. unsigned long sunGeneration = 0;
  139.  
  140. sunFbDataRec sunFbData[] = {
  141.     sunBW2Probe,      "/dev/bwtwo0",        sunBW2Create,
  142. #ifndef    sprite
  143.     sunCG2CProbe,      "/dev/cgtwo0",        sunCG2CCreate,
  144. #endif    sprite
  145.     sunCG3CProbe,      "/dev/cgthree0",    sunCG3CCreate,
  146.     sunCG6CProbe,    "/dev/cgsix0",        sunCG6CCreate,
  147.     sunCG4CProbe,      "/dev/cgfour0",        sunCG4CCreate,
  148.     sunBW2Probe,      "/dev/bwtwo0",        sunBW2Create,
  149. };
  150.  
  151. /*
  152.  * NUMSCREENS is the number of supported frame buffers (i.e. the number of
  153.  * structures in sunFbData which have an actual probeProc).
  154.  */
  155. #define NUMSCREENS (sizeof(sunFbData)/sizeof(sunFbData[0]))
  156. #define NUMDEVICES  2
  157.  
  158. fbFd sunFbs[NUMDEVICES];
  159.  
  160. static PixmapFormatRec    formats[] = {
  161.     1, 1, BITMAP_SCANLINE_PAD,    /* 1-bit deep */
  162.     8, 8, BITMAP_SCANLINE_PAD,    /* 8-bit deep */
  163. };
  164. #define NUMFORMATS    (sizeof formats)/(sizeof formats[0])
  165.  
  166. /*-
  167.  *-----------------------------------------------------------------------
  168.  * sunNonBlockConsoleOff --
  169.  *    Turn non-blocking mode on the console off, so you don't get logged
  170.  *    out when the server exits.
  171.  *
  172.  * Results:
  173.  *    None.
  174.  *
  175.  * Side Effects:
  176.  *    None.
  177.  *
  178.  *-----------------------------------------------------------------------
  179.  */
  180. /*ARGSUSED*/
  181. sunNonBlockConsoleOff(arg)
  182.     char    *arg;
  183. {
  184.     register int i;
  185.  
  186. #ifndef    sprite
  187.     i = fcntl(2, F_GETFL, 0);
  188.     if (i >= 0)
  189.     (void) fcntl(2, F_SETFL, i & ~FNDELAY);
  190. #endif    sprite
  191. }
  192.  
  193. /*-
  194.  *-----------------------------------------------------------------------
  195.  * InitOutput --
  196.  *    Initialize screenInfo for all actually accessible framebuffers.
  197.  *    The
  198.  *
  199.  * Results:
  200.  *    screenInfo init proc field set
  201.  *
  202.  * Side Effects:
  203.  *    None
  204.  *
  205.  *-----------------------------------------------------------------------
  206.  */
  207.  
  208. InitOutput(pScreenInfo, argc, argv)
  209.     ScreenInfo       *pScreenInfo;
  210.     int           argc;
  211.     char          **argv;
  212. {
  213.     int           i, n, dev;
  214.     int          nonBlockConsole = 1;
  215.     static int      setup_on_exit = 0;
  216.     int          devStart = 1;
  217.  
  218.     if (!monitorResolution)
  219.     monitorResolution = 90;
  220.     for (i = 1; i < argc; i++) {
  221.     if (!strcmp(argv[i],"-debug"))
  222.         nonBlockConsole = 0;
  223.     else if (!strcmp(argv[i],"-mono"))
  224.         devStart = 0;
  225.     }
  226. #ifndef    sprite
  227.     /*
  228.      *    Writes to /dev/console can block - causing an
  229.      *    excess of error messages to hang the server in
  230.      *    deadlock.  So.......
  231.      */
  232.     if (nonBlockConsole) {
  233.     if (!setup_on_exit) {
  234.         if (on_exit(sunNonBlockConsoleOff, (char *)0))
  235.         ErrorF("InitOutput: can't register NBIO exit handler\n");
  236.         setup_on_exit = 1;
  237.     }
  238.     i = fcntl(2, F_GETFL, 0);
  239.     if (i >= 0)
  240.         i = fcntl(2, F_SETFL, i | FNDELAY);
  241.     if (i < 0) {
  242.         perror("fcntl");
  243.         ErrorF("InitOutput: can't put stderr in non-block mode\n");
  244.     }
  245.     }
  246. #endif    sprite
  247.     pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  248.     pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  249.     pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  250.     pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  251.  
  252.     pScreenInfo->numPixmapFormats = NUMFORMATS;
  253.     for (i=0; i< NUMFORMATS; i++)
  254.         pScreenInfo->formats[i] = formats[i];
  255.  
  256.     autoRepeatHandlersInstalled = FALSE;
  257.  
  258.     if (!sunDevsProbed)
  259.     {
  260.     n = 0;
  261.     for (i = NUMSCREENS, dev = devStart; --i > 0; dev++) {
  262.         if ((*sunFbData[dev].probeProc)(pScreenInfo, n, dev, argc, argv))
  263.         n++;
  264.         else
  265.         sunFbData[dev].createProc = NULL;
  266.     }
  267.     sunDevsProbed = TRUE;
  268.     if (n == 0)
  269.         return;
  270.     }
  271.     if (!sunSupportsDepth8)
  272.     pScreenInfo->numPixmapFormats--;
  273.     for (i = NUMSCREENS, dev = devStart; --i > 0; dev++) {
  274.     if (sunFbData[dev].createProc)
  275.         (*sunFbData[dev].createProc)(pScreenInfo, argc, argv);
  276.     }
  277.     sunGeneration = serverGeneration;
  278.     sunInitCursor();
  279.     signal(SIGWINCH, SIG_IGN);
  280. }
  281.  
  282. /*-
  283.  *-----------------------------------------------------------------------
  284.  * InitInput --
  285.  *    Initialize all supported input devices...what else is there
  286.  *    besides pointer and keyboard?
  287.  *
  288.  * Results:
  289.  *    None.
  290.  *
  291.  * Side Effects:
  292.  *    Two DeviceRec's are allocated and registered as the system pointer
  293.  *    and keyboard devices.
  294.  *
  295.  *-----------------------------------------------------------------------
  296.  */
  297. /*ARGSUSED*/
  298. InitInput(argc, argv)
  299.     int           argc;
  300.     char          **argv;
  301. {
  302.     DevicePtr p, k;
  303.     static int  zero = 0;
  304.     
  305.     p = AddInputDevice(sunMouseProc, TRUE);
  306.     k = AddInputDevice(sunKbdProc, TRUE);
  307.     if (!p || !k)
  308.     FatalError("failed to create input devices in InitInput");
  309.  
  310.     RegisterPointerDevice(p);
  311.     RegisterKeyboardDevice(k);
  312.     miRegisterPointerDevice(screenInfo.screens[0], p);
  313.  
  314.     spriteCheckInput = 0;
  315.     SetInputCheck (&zero, &spriteCheckInput);
  316.  
  317.     screenInfo.screens[0]->blockData =
  318.     screenInfo.screens[0]->wakeupData = (pointer)k;
  319. }
  320.  
  321. /*-
  322.  *-----------------------------------------------------------------------
  323.  * sunScreenInit --
  324.  *    Things which must be done for all types of frame buffers...
  325.  *    Should be called last of all.
  326.  *
  327.  * Results:
  328.  *    TRUE if successful, else FALSE
  329.  *
  330.  * Side Effects:
  331.  *    Both a BlockHandler and a WakeupHandler are installed for the
  332.  *    first screen.  Together, these handlers implement autorepeat
  333.  *    keystrokes on the Sun.
  334.  *
  335.  *-----------------------------------------------------------------------
  336.  */
  337. Bool
  338. sunScreenInit (pScreen)
  339.     ScreenPtr      pScreen;
  340. {
  341.     extern void   sunBlockHandler();
  342.     extern void   sunWakeupHandler();
  343.     static ScreenPtr autoRepeatScreen;
  344.     extern miPointerCursorFuncRec   sunPointerCursorFuncs;
  345.  
  346.     /*
  347.      *    Block/Unblock handlers
  348.      */
  349.     if (autoRepeatHandlersInstalled == FALSE) {
  350.     autoRepeatScreen = pScreen;
  351.     autoRepeatHandlersInstalled = TRUE;
  352.     }
  353.  
  354.     if (pScreen == autoRepeatScreen) {
  355.         pScreen->BlockHandler = sunBlockHandler;
  356.         pScreen->WakeupHandler = sunWakeupHandler;
  357.     }
  358.  
  359.     miDCInitialize (pScreen, &sunPointerCursorFuncs);
  360.  
  361. #ifdef SUN_WINDOWS
  362.     /*
  363.      * We need to wrap one of the cursor functions so that
  364.      * we can keep the SunWindows cursor position in sync
  365.      * with X. We still call the mi version to do the real
  366.      * work.
  367.      */
  368.     realSetCursorPosition = pScreen->SetCursorPosition;
  369.     pScreen->SetCursorPosition = sunSetCursorPosition;
  370. #endif
  371.  
  372.     return TRUE;
  373. }
  374.  
  375.  
  376. extern char *getenv();
  377.  
  378. /*-
  379.  *-----------------------------------------------------------------------
  380.  * nthdev --
  381.  *    Return the nth device in a colon-separated list of devices.
  382.  *    n is 0-origin.
  383.  *
  384.  * Results:
  385.  *    A pointer to a STATIC string which is the device name.
  386.  *
  387.  * Side Effects:
  388.  *    None.
  389.  *
  390.  *-----------------------------------------------------------------------
  391.  */
  392. static char *
  393. nthdev (dList, n)
  394.     register char    *dList;        /* Colon-separated device names */
  395.     int        n;              /* Device number wanted */
  396. {
  397.     char *result;
  398.     static char returnstring[100];
  399.  
  400.     while (n--) {
  401.     while (*dList && *dList != ':') {
  402.         dList++;
  403.     }
  404.     }
  405.     if (*dList) {
  406.     register char *cp = dList;
  407.  
  408.     while (*cp && *cp != ':') {
  409.         cp++;
  410.     }
  411.     result = returnstring;
  412.     strncpy (result, dList, cp - dList);
  413.     result[cp - dList] = '\0';
  414.     } else {
  415.     result = (char *)0;
  416.     }
  417.     return (result);
  418. }
  419.  
  420. /*-
  421.  *-----------------------------------------------------------------------
  422.  * sunOpenFrameBuffer --
  423.  *    Open a frame buffer according to several rules. If running under
  424.  *    overview and we're set up for it, use the device given in the
  425.  *    PARENT envariable and note that the screen is under overview.
  426.  *    Else find the device to use by looking in the sunFbData table,
  427.  *    an XDEVICE envariable, a -dev switch or using /dev/fb if trying
  428.  *    to open screen 0 and all else has failed.
  429.  *
  430.  * Results:
  431.  *    The fd of the framebuffer.
  432.  *
  433.  * Side Effects:
  434.  *
  435.  *-----------------------------------------------------------------------
  436.  */
  437. int
  438. sunOpenFrameBuffer(expect, pfbType, index, fbNum, argc, argv)
  439.     int              expect;       /* The expected type of framebuffer */
  440.     struct fbtype *pfbType;     /* Place to store the fb info */
  441.     int              fbNum;        /* Index into the sunFbData array */
  442.     int              index;        /* Screen index */
  443.     int              argc;            /* Command-line arguments... */
  444.     char      **argv;       /* ... */
  445. {
  446.     char             *name=(char *)0;
  447.     int           i;            /* Index into argument list */
  448.     int           fd = -1;            /* Descriptor to device */
  449.     static int      devFbUsed=FALSE;  /* true if /dev/fb has been used for a */
  450.                                   /* screen already */
  451.     static Bool      inited = FALSE;
  452.     static char      *xdevice;     /* string of devices to use from environ */
  453.     static char      *devsw;       /* string of devices from args */
  454.     struct fbgattr  fbattr;
  455.     int          type;
  456.  
  457.     sunFbs[index].parent = FALSE;
  458.  
  459.     if (!inited) {
  460.     xdevice = devsw = (char *)NULL;
  461.  
  462.     xdevice = getenv (XDEVICE);
  463.     /*
  464.      * Look for an argument of the form -dev <device-string>
  465.      * If such a one is found place the <device-string> in devsw.
  466.      */
  467.     for (i = 1; i < argc; i++) {
  468.         if ((strcmp(argv[i], "-dev") == 0) && (i + 1 < argc)) {
  469.         devsw = argv[i+1];
  470.         break;
  471.         }
  472.     }
  473.     inited = TRUE;
  474.     }
  475.  
  476.     /*
  477.      * Attempt to find a file name for the frame buffer 
  478.      */
  479.  
  480.     /*
  481.      * First see if any device was given on the command line.
  482.      * If one was and the device is both readable and writeable,
  483.      * set 'name' to it, else set it to NULL.
  484.      */
  485.     if (devsw == (char *)NULL ||
  486.     (name = nthdev (devsw, index)) == (char *)NULL ||
  487.     (access (name, R_OK | W_OK) != 0) ||
  488.     (strcmp(name, sunFbData[fbNum].devName) != 0)) {
  489.         name = (char *)NULL;
  490.     }
  491.         
  492.     /*
  493.      * If we still don't have a device for this screen, check the
  494.      * environment variable for one. If one was given, stick its
  495.      * path in name and check its accessibility. If it's not
  496.      * properly accessible, then reset the name to NULL to force the
  497.      * checking of the sunFbData array.
  498.      */
  499.     if (devsw == (char *)NULL && name == (char *)NULL &&
  500.     xdevice != (char *)NULL &&
  501.     (name = nthdev(xdevice, index)) != (char *)NULL &&
  502.     (access (name, R_OK | W_OK) != 0)) {
  503.         name = (char *)NULL;
  504.     }
  505.  
  506.     /*
  507.      * Take the device given in the frame buffer description
  508.      * and see if it exists and is accessible. If it does/is,
  509.      * we will use it, as long as no other device was given.
  510.      */
  511.     if (devsw == (char *)NULL && name == (char *)NULL &&
  512.     access(sunFbData[fbNum].devName, (R_OK | W_OK)) == 0) {
  513.         name = sunFbData[fbNum].devName;
  514.     }
  515.  
  516.     /*
  517.      * If we still have nothing and have yet to use "/dev/fb" for
  518.      * a screen, default the name to be "/dev/fb"
  519.      */
  520.     if (devsw == (char *)NULL && name == (char *)NULL && !devFbUsed) {
  521.     name = "/dev/fb";
  522.     }
  523.  
  524.  
  525.     if (name != (char *) NULL && sunUseSunWindows()) {
  526. #ifdef    SUN_WINDOWS
  527.  
  528.     /*
  529.      * Running X in coexistence with SunWindows.
  530.      *
  531.      * This section of code enables X to run with SunWindows.  This is 
  532.      * accomplished by opening up screens and windows in the SunWindows 
  533.      * style and accepting input events from them.  However, since the X 
  534.      * graphics libraries want a raw framebuffer, we open the 
  535.      * framebuffer of the current screen and return that.  So we get 
  536.      * input from SunWindows but send output to the raw framebuffer.
  537.      */
  538.  
  539.     char       *parent = getenv("WINDOW_PARENT");
  540.     struct screen sc;
  541.     int        winFd;
  542.     int        parentFd;
  543.     int        framebufferFd;
  544.     Rect        r;
  545.     static struct screen newScreen;
  546.     struct inputmask inputMask;
  547.     Bool        keepParent = FALSE;
  548.     static int  sunFbFound = 0;    /* True if FB found under SunWindows */
  549.  
  550.     /*
  551.      * If no device was specified on the command line, open the window 
  552.      * specified in WINDOW_PARENT.  If a device was specified, open a 
  553.      * new screen on that device and use it as a parent window.
  554.      */
  555.  
  556.     if ( devsw ) {
  557.         bzero( (caddr_t)&newScreen, sizeof(newScreen) );
  558.         strcpy( newScreen.scr_fbname, name );
  559.         newScreen.scr_flags |= SCR_TOGGLEENABLE;
  560.         if ( (parentFd = win_screennew( &newScreen )) < 0 ) {
  561.         ErrorF( "sunOpenFrameBuffer: Can't open new screen on %s.\n",
  562.             name );
  563.         return( -1 );
  564.         }
  565.         keepParent = TRUE;
  566.     } else {
  567.         if ((parentFd = open(parent, 2, 0)) < 0) {
  568.         ErrorF("sunOpenFrameBuffer: Can't open parent %s.\n", parent);
  569.         return (-1);
  570.         }
  571.     }
  572.  
  573.     if ((winFd = win_getnewwindow()) < 0) {
  574.         ErrorF("sunOpenFrameBuffer: Can't open a new window.\n");
  575.         close( parentFd );
  576.         return (-1);
  577.     }
  578.  
  579.     /* link the new window into the window hierarchy */
  580.     bzero((caddr_t) & r, sizeof r);
  581.     win_getrect(parentFd, &r);
  582.     win_setrect(winFd, &r);
  583.     win_setlink(winFd, WL_PARENT, win_fdtonumber(parentFd));
  584.     win_setlink(winFd, WL_OLDERSIB, win_getlink(parentFd, WL_TOPCHILD));
  585.     sunFbs[index].parent = TRUE;
  586.  
  587.     /*
  588.      * We would like to close the parent window here, since it's no 
  589.      * longer needed.  However, in the case where the parent is really a 
  590.      * screen, we have to keep it open, because closing a screen closes 
  591.      * all the windows on that screen.
  592.      */
  593.  
  594.     if ( ! keepParent )
  595.         close(parentFd);
  596.     
  597.     /*
  598.      * Express interest in SunView mouse events.  Note: the win_insert 
  599.      * must be AFTER setting the input mask in order to receive the 
  600.      * initial LOC_WINENTER event.
  601.      */
  602.  
  603.     input_imnull(&inputMask);
  604.     inputMask.im_flags = IM_ASCII | IM_META | IM_NEGEVENT | IM_INTRANSIT;
  605.  
  606.     win_setinputcodebit(&inputMask, LOC_MOVE);
  607.     win_setinputcodebit(&inputMask, LOC_WINEXIT);
  608.     win_setinputcodebit(&inputMask, LOC_WINENTER);
  609.     win_setinputcodebit(&inputMask, MS_LEFT);
  610.     win_setinputcodebit(&inputMask, MS_MIDDLE);
  611.     win_setinputcodebit(&inputMask, MS_RIGHT);
  612.     win_set_pick_mask(winFd, &inputMask);
  613.  
  614.     input_imnull(&inputMask);
  615.     win_setinputcodebit(&inputMask, KBD_USE);
  616.     win_setinputcodebit(&inputMask, KBD_DONE);
  617.     win_set_kbd_mask(winFd, &inputMask);
  618.  
  619.     win_insert(winFd);
  620.  
  621.     /*
  622.      * Determine the framebuffer name from the window's screen, then 
  623.      * open it.  Then do an FBIOGTYPE ioctl to determine its type.
  624.      */
  625.  
  626.     win_screenget( winFd, &sc );
  627.     if ((framebufferFd = open(sc.scr_fbname, O_RDWR, 0)) < 0) {
  628.         ErrorF("sunOpenFrameBuffer: can't open %s\n",sc.scr_fbname);
  629.         (void) close(winFd);
  630.         (void) close(parentFd);
  631.         return (-1);
  632.     }
  633.  
  634.     if (ioctl(framebufferFd, FBIOGTYPE, pfbType) < 0) {
  635.         perror("sunOpenFrameBuffer: FBIOGTYPE");
  636. badfb:
  637.         (void) close(framebufferFd);
  638.         (void) close(winFd);
  639.         (void) close(parentFd);
  640.         return (-1);
  641.     }
  642.  
  643.     if (pfbType->fb_type != expect) {
  644.         struct fbgattr fbgattr;
  645.         int i;
  646.  
  647.         /*
  648.          * On a 3/110 we only want to open one display
  649.          * on /dev/fb (or /dev/cgfour0) if no device is
  650.          * specified in the command line.  If not, we won't
  651.          * be able to slide back and forth between X displays
  652.          * since only one SunWindows framebuffer is open.
  653.          * The screen that is opened is /dev/bwtwo0.
  654.          */
  655.         if (sunFbFound && (devsw == (char *) NULL))
  656.         goto badfb;
  657.  
  658.         if (ioctl(framebufferFd, FBIOGATTR, &fbgattr) < 0)
  659.         goto badfb;
  660.         
  661.         for (i=0; i<FB_ATTR_NEMUTYPES; i++)
  662.         if (fbgattr.emu_types[i] == expect)
  663.             break;
  664.         else if (fbgattr.emu_types[i] == -1)
  665.             goto badfb;
  666.     }
  667.         /*
  668.      * NDELAY only applies to "input" fds, or fds that can be
  669.      * read.  sunwindows fds are read, while frame buffer fds aren't.
  670.      * That's why this fcntl is in the conditional compilation section.
  671.      */
  672.  
  673.     if (fcntl(winFd, F_SETFL, FNDELAY|FASYNC) < 0) {
  674.         ErrorF("Can't set FNDELAY|FASYNC on %s\n",name);
  675.         perror("sunOpenFrameBuffer");
  676.         (void) close(winFd);
  677.         return (-1);
  678.     }
  679.     
  680.     fd = framebufferFd;
  681.     windowFd = winFd;
  682.     sunFbFound++;
  683. #else
  684.     ErrorF("Not configured to run inside SunWindows\n");
  685.     fd = -1;
  686. #endif    SUN_WINDOWS
  687.     } else if (name) {
  688.     fd = open(name, O_RDWR, 0);
  689.         if (fd < 0) {
  690.         return (-1);
  691.     } 
  692.     if (ioctl(fd, FBIOGATTR, &fbattr) < 0)
  693.     {
  694.         if (ioctl(fd, FBIOGTYPE, pfbType) < 0) {
  695.         perror("sunOpenFrameBuffer");
  696.         (void) close(fd);
  697.         return (-1);
  698.         }
  699.         type = pfbType->fb_type;
  700.  
  701.         printf("Framebuffer=|%s|, type = %d\n", name, type);
  702.  
  703.     }
  704.     else
  705.     {
  706.         int    i;
  707.  
  708.         type = fbattr.real_type;
  709.         *pfbType = fbattr.fbtype;
  710.         if (expect == FBTYPE_SUN2BW && expect != type)
  711.         {
  712.             for (i = 0; i < FB_ATTR_NEMUTYPES; i++)
  713.             {
  714.             if (expect == fbattr.emu_types[i])
  715.             {
  716.                 type = fbattr.emu_types[i];
  717.             break;
  718.             }
  719.             }
  720.         }
  721.     }
  722.     /* XXX - this is temporary 'cos the CG4 pretends its a BW2 */
  723.     if (strcmp(name, sunFbData[fbNum].devName) != 0 && type != expect)
  724.     {
  725.         (void) close(fd);
  726.         return (-1);
  727.     }
  728.     }
  729.  
  730.     if (name && strcmp (name, "/dev/fb") == 0) {
  731.     devFbUsed = TRUE;
  732.     }
  733.  
  734.     return (fd);
  735. }
  736. @
  737.  
  738.  
  739. 1.5
  740. log
  741. @New frame buffer changes.
  742. @
  743. text
  744. @d646 3
  745. a648 3
  746.             perror("sunOpenFrameBuffer");
  747.             (void) close(fd);
  748.             return (-1);
  749. d651 3
  750. @
  751.  
  752.  
  753. 1.4
  754. log
  755. @Works on treason.
  756. @
  757. text
  758. @a95 1
  759. #ifdef NOTDEF
  760. a96 2
  761. #endif NOTDEF
  762.     sunCG3CProbe,      "/hosts/treason/dev/fbthing",    sunCG3CCreate,
  763. @
  764.  
  765.  
  766. 1.3
  767. log
  768. @Mary checking this in for Mendel before adding /dev/fb.
  769. @
  770. text
  771. @d58 8
  772. d96 1
  773. d98 2
  774. a373 1
  775. #ifndef    sprite
  776. a686 1
  777. #endif    sprite
  778. @
  779.  
  780.  
  781. 1.2
  782. log
  783. @*** empty log message ***
  784. @
  785. text
  786. @d63 1
  787. a64 1
  788. #endif    sprite
  789. d87 1
  790. a88 1
  791. #endif    sprite
  792. @
  793.  
  794.  
  795. 1.1
  796. log
  797. @Initial revision
  798. @
  799. text
  800. @d51 1
  801. d61 1
  802. d64 1
  803. a65 1
  804. #ifdef FBTYPE_SUNFAST_COLOR /* doesn't exist in sunos3.x */
  805. a66 1
  806. #endif
  807. d76 1
  808. a76 1
  809. int sunSigIO = 0;     /* For use with SetInputCheck */
  810. a82 24
  811.  
  812. /*-
  813.  *-----------------------------------------------------------------------
  814.  * SigIOHandler --
  815.  *    Signal handler for SIGIO - input is available.
  816.  *
  817.  * Results:
  818.  *    sunSigIO is set - ProcessInputEvents() will be called soon.
  819.  *
  820.  * Side Effects:
  821.  *    None
  822.  *
  823.  *-----------------------------------------------------------------------
  824.  */
  825. /*ARGSUSED*/
  826. static void
  827. SigIOHandler(sig, code, scp)
  828.     int        code;
  829.     int        sig;
  830.     struct sigcontext *scp;
  831. {
  832.     sunSigIO = 1;
  833. }
  834.  
  835. d85 1
  836. d88 1
  837. a88 1
  838. #ifdef FBTYPE_SUNFAST_COLOR
  839. a89 1
  840. #endif
  841. d129 1
  842. d133 1
  843. d169 1
  844. d189 1
  845. d256 3
  846. a258 1
  847.     signal(SIGIO, SigIOHandler);
  848. d260 2
  849. a261 1
  850.     SetInputCheck (&zero, &sunSigIO);
  851. d363 1
  852. d677 1
  853. @
  854.